﻿<?php
require_once(dirname(__FILE__)."/../../libs/login/login.php");  
require_once(dirname(__FILE__)."/../../libs/dbclass/dbconnect.php");
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../../libs/string/pager.php");
$lg=new login();
$lg->checklogin("admin_member");//检验是否登录
$mc=new libstr();
$pg=new pager();
?>

<?php

if(isset($_GET["del"])&&$_GET["del"]!="")
{
//含有商品的不能删除 ，以后在做
//	$myrs4=$db->dvstr("select (select count(p.id) as ok from product_content as p where p.guanlian=c.ID) myok from guanlian_class as c where rootid ='".$_GET["del"]."' ");
//	if(trim($myrs4["myok"])>0)
//	{
//		$mc->msg("此类别不允许删除","go");
//	}
	//exit();
	$myrs5=$db->dvstr("select pid from guanlian_class where ID ='".$_GET["cataid"]."' ");
	$sqlstr="delete from guanlian_class where rootid like '%".$_GET["del"]."%'";
	$db->cmd($sqlstr);
	$mc->msg("","guanlian_class.php?cataid=".$myrs5["pid"]);
}
if(isset($_POST["btn"])&&$_POST["btn"]!="")
{
	$getrs=$dbs->ds("select * from guanlian_class where ID in(".$mc->getid("getid").")");
	foreach ($getrs as $rs1)
	{
		$dbs->cmd("update guanlian_class set classorder =".$_POST["classorder".$rs1["ID"]]." where ID=".$rs1["ID"]."");
	}
	$mc->msg("","guanlian_class.php?cataid=".$_GET["cataid"]);
}


$_where="";
$mypid="0";
if($mc->Ismp($_GET["cataid"])!="")
{
	$mypid=$_GET["cataid"];
}
if($mc->Ismp($_GET["key"])!="")
{
$_where.="   classname like '%".$mc->Ismp($_GET["key"]."%'");
}
$_tb="guanlian_class";
//echo $_where;
$order=" order by ID desc";
$pagesize=8;
$page=1;
if($mc->Ismp($_GET["page"])!=""){
	$page=$_GET["page"];
}

//echo $_where;
//exit();
$totalcount=$db->getcount("ID",$_tb,$_where);
$clrs=$db->pagerds("*",$_tb,$_where,$order,$totalcount,$pagesize,$page);
//print_r($clrs);
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link href="../css/Admin_Style.css" rel="stylesheet" type="text/css">

<script>
function adduserno(str,str1)
{
parent.document.getElementById("guanlianstr").value=(str1);
parent.document.getElementById("guanlianid").value=(str);
}

function GP_popupConfirmMsg(msg) { //v1.0
        	document.MM_returnValue = confirm(msg);

        }
</script>
</head>

<body >
<form name="form1" method="get" action="" style="margin:0px">
  <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
  <tr>
    <td><table width="98%" border="0" align="center">
      <tr>
        <td width="85%" height="20">关键词
          <input type="text" name="key" id="key" />
          <input type="submit" name="cd" id="cd" value="搜索" /></td>
        <td width="15%"><div align="right"><a href="guanlian_class_creat.php?id=<?php echo $mc->Ismp($_GET["cataid"]);?>&url=guanlian_class">添加新类&gt;&gt;</a></div></td>
      </tr>
    </table></td>
  </tr>
</table>
  
  <table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="5"></td> </tr>
  </table>
  <?php if ($totalcount > 0) {?>
  <table width="98%" height="47" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
    <tr >
      <td width="9%" align="center" bgcolor="#F6F6F6" ><strong>ID</strong></td> 
      <td width="40%" height="25" align="left" bgcolor="#F6F6F6" ><strong> &nbsp;关联名称</strong></td>
      <td width="25%" bgcolor="#F6F6F6" ><strong>关联产品数量</strong></td>
      <td width="25%" bgcolor="#F6F6F6" > <div align="center"></div></td>
    </tr> <?php
    foreach($clrs as $rsch){
	?> <tr bgcolor="#ffffff" onMouseOver="this.style.backgroundColor='#E7FEFA';" onMouseOut="this.style.backgroundColor='';">
      <td align="center" style='border-bottom:1px; border-bottom-color:#CCCCCC; border-bottom-style:dashed'><?php echo $rsch["ID"];?></td>
      <td height="23" style='border-bottom:1px; border-bottom-color:#CCCCCC; border-bottom-style:dashed'>&nbsp;<?php echo $rsch["classname"];?></td>
      <td style='border-bottom:1px; border-bottom-color:#CCCCCC; border-bottom-style:dashed'><?php 
	  $kds=$db->dvstr("select count(id) as ok from product_content where guanlian=".$rsch["ID"]);
	  echo $kds["ok"];?>
      &nbsp;[<a href="guanlian.php?id=<?php echo $rsch["ID"];?>&url=guanlian_class&page= <?php echo $page;?>"" >查看</a>]</td>
      <td style='border-bottom:1px; border-bottom-color:#CCCCCC; border-bottom-style:dashed'><div align="center"><input type="button" name="search2" id="search2" value="选择"  onclick="adduserno('<?php echo $rsch["ID"]?>','<?php echo $rsch["classname"]?>');art.dialog.close();
"/>
     <a href="guanlian_class_edit.php?id=<?php echo $rsch["ID"];?>&url=guanlian_class&page= <?php echo $page;?>">修改</a>   <a href='?cataid=<?php echo $rsch["ID"];?>&del=<?php echo $rsch["rootid"];?>&classid=' onClick="GP_popupConfirmMsg('您真的要删除吗？');return document.MM_returnValue">删除</a></div></td></tr>  <?php
	}
	?>  <tr bgcolor="#CCCCCC"> 
      <td height="30" colspan="4" align="right" bgcolor="#FFFFFF" style="padding-right:5px"><?php 
                    $pg->isre=false;
        echo $pg->fp("",$totalcount,$pagesize,"","");?>
        <?php echo $pg->pp("",$totalcount,$pagesize,"","");?> <?php echo $pg->fstr("",$totalcount, $pagesize, 5, "");?> <?php echo $pg->np("",$totalcount,$pagesize,"","");?> <?php echo $pg->lp("",$totalcount,$pagesize,"","");?> 显示 <?php echo $pg->startid("",$totalcount, $pagesize);?> -
        <?php 
echo $pg->endid("",$totalcount, $pagesize);?>
第 <?php echo $pg->spage("",$totalcount, $pagesize);?> 页/共 <?php echo $pg->pagecount("",$totalcount, $pagesize)?> 页
    共 <?php echo $totalcount ;?> 条,<?php echo $pg->gopage("","跳到 * 页","width:30px;text-align: center;border:1px solid #ababab;","Go","height:20px;width:25px;");?> </td>
    </tr>
  </table>
  <?php }else{?>
  <table width="100%" border="0">
    <tr>
      <td align="center">没有找到相应的关联类别，请添加。</td>
    </tr>
  </table>
  <?php }?>
</form>
</body>
</html>
